<%@page contentType="text/html"%>  
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>  
<%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>  
<%@taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
"http://www.w3.org/TR/html4/loose.dtd">  
<html>
    <head>
        <title>Produto</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="cache-control" content="no-store">
        <meta http-equiv="expires" content="0">

        <script type="text/javascript" src="../../_js/dFilter.js"></script>
        <script type="text/javascript" src="../../_js/valores.js"></script>
    </head>
    <style type="text/css"><!--@import url("../../_css/style.css");--></style>
    <style>
        .panelModal {
            vertical-align:top;
            width:600px;
            height:470px;
        }
    </style>
    <body>
        <f:view>
            <t:saveState id="_bean" value="#{ProdutoBean}" />
            <rich:panel>
                <f:facet name="header">
                    <h:outputText value="Produto"/>
                </f:facet>
                <a4j:form status="modalStatus">
                    <h:inputHidden value="#{ProdutoBean.id}" id="id"/>
                    <t:panelGrid columns="4">
                        <t:column width="15%">
                            <h:outputLabel value="Marca *" for="marcaId"/>
                        </t:column>
                        <t:column width="35%">
                            <h:inputText value="#{ProdutoBean.marcaDescricao}" id="marcaDescricao" style="width:380px;" readonly="true" onclick="Richfaces.showModalPanel('modalMarca')"/>
                            <h:inputHidden value="#{ProdutoBean.marcaId}" id="marcaId" required="true" requiredMessage="Marca é um campo requerido."/>&nbsp;&nbsp;
                            <a4j:commandButton image="../../_images/btn_pesquisar.png" title="Pesquisar" immediate="true" ajaxSingle="true" onclick="Richfaces.showModalPanel('modalMarca')"/>
                        </t:column>
                        <t:column width="15%">&nbsp;</t:column>
                        <t:column width="35%">&nbsp;</t:column>
                        
                        <t:column width="15%"><h:outputLabel value="Descrição *" for="descricao"/></t:column>
                        <t:column width="35%">
                            <h:inputText value="#{ProdutoBean.descricao}" id="descricao" required="true" maxlength="40" style="width:400px;" requiredMessage="Descrção é um campo requerido."/>
                        </t:column>
                        <t:column width="15%">&nbsp;</t:column>
                        <t:column width="35%">&nbsp;</t:column>

                        <t:column width="15%"><h:outputLabel value="Valor Compra *" for="valorCompra"/></t:column>
                        <t:column width="15%">
                            <h:inputText value="#{ProdutoBean.valorCompra}" id="valorCompra" label="Valor Suposto" maxlength="12" onkeypress="reais(this,event,13)" onkeydown="backspace(this,event)" required="true" requiredMessage="Campo Requerido.">
                                <f:convertNumber pattern="#,##0.00"></f:convertNumber>
                            </h:inputText>
                        </t:column>
                        <t:column width="15%"><rich:message for="valorCompra" style="color:red;"/></t:column>
                        <t:column width="35%">&nbsp;</t:column>

                        <t:column width="15%"><h:outputLabel value="Valor Venda *" for="valorVenda"/></t:column>
                        <t:column width="15%">
                            <h:inputText value="#{ProdutoBean.valorVenda}" id="valorVenda" label="Valor Suposto" maxlength="12" onkeypress="reais(this,event,13)" onkeydown="backspace(this,event)" required="true" requiredMessage="Campo Requerido.">
                                <f:convertNumber pattern="#,##0.00"></f:convertNumber>
                            </h:inputText>
                        </t:column>
                        <t:column width="15%"><rich:message for="valorSuposto" style="color:red;"/></t:column>
                        <t:column width="35%">&nbsp;</t:column>

                        <t:column width="15%"><h:outputLabel value="Tamanho *" for="tamanho"/></t:column>
                        <t:column width="35%">
                            <h:inputText value="#{ProdutoBean.tamanho}" id="tamanho" required="true" maxlength="3" style="width:40px;" requiredMessage="Tamanho é um campo requerido."/>
                        </t:column>
                        <t:column width="15%">&nbsp;</t:column>
                        <t:column width="35%">&nbsp;</t:column>

                    </t:panelGrid>
                    <rich:messages styleClass="erro" style="color:red;"/>
                    <br>
                    <a4j:commandButton value="Salvar" action="#{ProdutoBean.salvar}"/>&nbsp;&nbsp;
                    <a4j:commandButton value="Retornar" action="#{ProdutoBean.retornar}" immediate="true"/>&nbsp;&nbsp;
                </a4j:form>
            </rich:panel>

            <rich:modalPanel id="modalMarca" zindex="19999" left="20px" top="20px" autosized="true">
                <a4j:form id="frmProdutoMarca">
                    <rich:panel styleClass="panelModal">
                        <f:facet name="header">
                            <h:outputText value="Marca" />
                        </f:facet>
                        <center>
                            <h:outputLabel value="Descrição"/>&nbsp;&nbsp;
                            <h:inputText value="#{ProdutoBean.marcaDescricaoPesq}" id="marcaDescricaoPesq" style="width:150px;"/>&nbsp;&nbsp;
                            <a4j:commandButton value="Pesquisar" onclick="Richfaces.showModalPanel('modalMarca')" action="#{ProdutoBean.pesquisarMarca}" reRender="frmProdutoMarca"/>&nbsp;&nbsp;
                            <h:commandButton value="Fechar" onclick="Richfaces.hideModalPanel('modalMarca')" action="#{ProdutoBean.pesquisarMarca}"/>
                        </center>
                        <br>
                        <rich:dataTable id="tblProdutoMarca" value="#{ProdutoBean.listaMarcas}" width="100%" var="list"
                        columns="3" rows="13" rowKeyVar="rowKey" reRender="ds">
                            <rich:column width="40px" sortBy="#{list.id}">
                                <f:facet name="header"><h:outputText value="ID"/></f:facet>
                                <h:outputText value="#{list.id}"/>
                            </rich:column>
                            <rich:column sortBy="#{list.descricao}">
                                <f:facet name="header"><h:outputText value="Descrição"/></f:facet>
                                <h:outputText value="#{list.descricao}"/>
                            </rich:column>
                            <rich:column width="20px">
                                <f:facet name="header"><h:outputText value="Sel"/></f:facet>
                                <a4j:commandButton image="../../_images/btn_selecionar.gif" binding="#{ProdutoBean.btnSelecionar}" title="Selecionar" value="#{list.id},#{list.descricao}" ajaxSingle="true" action="#{ProdutoBean.selecionarMarca}" onclick="Richfaces.hideModalPanel('modalMarca')" reRender="marcaId,marcaDescricao"/>
                            </rich:column>

                            <f:facet name="footer">
                                <rich:datascroller id="ds"></rich:datascroller>
                            </f:facet>
                        </rich:dataTable>
                    </rich:panel>
                </a4j:form>
            </rich:modalPanel>
            
            <a4j:status id="modalStatus" onstart="Richfaces.showModalPanel('ajaxLoadingModalBox')"
            onstop="Richfaces.hideModalPanel('ajaxLoadingModalBox')" />
            <rich:modalPanel id="ajaxLoadingModalBox" zindex="20000" autosized="true">
                <h:outputText value="Carregando"/><br>
                <h:graphicImage value="../../_images/img_load.gif"/>
            </rich:modalPanel>
        </f:view>
    </body>
</html>